﻿/*创 建 人：LiuY
创建时间：2013-3-14
案例说明：获取网站后台配置
function GetConfig(name) {
var str = GetServerData( "SystemConfig", "GetConfig", name,"c");
return str;
}

参数说明：类,方法,参数,命名空间（可选：默认:b:Bussiness；c:Common；d:Data；u:UnitTest；w:WriteLog）,回调函数（可选）
*/

var request = {
    QueryString: function (val) {
        var uri = window.location.search;
        var re = new RegExp("" + val + "=([^&?]*)", "ig");
        return ((uri.match(re)) ? (uri.match(re)[0].substr(val.length + 1)) : null);
    }
}

var strRootPath = Common.GetRootPath();//webservice起始路径
var strUserid= request.QueryString("userid");
//获取当前日期
var date = new Date();
var strDqrq = date.toLocaleDateString();

function GetServerData(clssname, method, parameters, assembly, callback) {
    var _val = "";
    if (!assembly) {
        assembly = "m";
    }
    $.ajax({
        type: "POST",
        contentType: "application/json",
        url: strRootPath+"WebService/MainService.asmx/AjaxMethod",
        data: '{ asb: "' + assembly + '", cls: "' + clssname + '", mth: "' + method + '", param: "' + parameters + '" }',
        dataType: 'json',
        async: false,
        error: function(message) {
            alert(message.responseText);
        },
        success: function(data) {
            if (!callback || callback == undefined || callback == "") {
                _val = data.d;
            }
            else {
                callback(data.d);
            }
        }
    });
    return _val;
};

function GetServerDataJson(clssname, method, parameters, assembly, callback) {
    var _val = "";
    if (!assembly) {
        assembly = "m";
    }
    $.ajax({
        type: "POST",
        contentType: "application/json",
        url: strRootPath+"WebService/MainService.asmx/AjaxMethodJson",
        data: '{ asb: "' + assembly + '", cls: "' + clssname + '", mth: "' + method + '", param:"' + parameters + '"}',
        dataType: 'json',
        async: false,
        error: function(message) {
            alert(message.responseText);
        },
        success: function(data) {
            if (!callback || callback == undefined || callback == "") {
                _val = data.d;
            }
            else {
                callback(data.d);
            }
        }
    });
    return _val;
};

//请求service通用方法
function GetServiceData(method, parameters, callback,loadItemId) {
    var _val = ""; 
    $.ajax({
        type: "POST",
        contentType: "application/json",
        url: strRootPath+"WebService/MainService.asmx/" + method,
        data: parameters,
        dataType: 'json',
        async: false,
        error: function (message) {
            alert(message.responseText);
        },
        success: function (data) {
            if (!callback || callback == undefined || callback == "") {
                _val = data.d; 
            }
            else {
                callback(loadItemId,data.d);
            }
        }
    });
    return _val;
};

//获取dataTable并返回json
function CommonData(clssname, method, parameters,cbFun) {
    var json = GetServerData(clssname, method, parameters, "m", cbFun);
    return json;
}

//解析Json格式并构建table数据(行政许可事项列表)
function createCommonTable(strDivId, json) {
    json = json.toJson(); //格式化
    var table = $("<table></table>");
    for (var i = 0; i < json.length; i++) {
        o1 = json[i];
        var row = $("<tr></tr>");
        for (key in o1) {
            var td = $("<td></td>");
            td.text(o1[key].toString());
            td.appendTo(row);
        }
        row.appendTo(table);
    }
    table.appendTo($("#" + strDivId));
}

//获取发布内容
function GetContent(json) {
    json = json.toJson(); //格式化

    for (var i = 0; i < json.length; i++) {
        o1 = json[i];
        $("#h3Title").html(o1["title"].toString());
        $("#divContent").html(o1["content"].toString());
    }
}

function RedirectBySerial(nType)
{
    var strUrl = "";
    switch(nType)
    {
        case 1:
            strUrl = "main.html?userid="+strUserid;
            break;
        case 2:
            strUrl = "baoxiao.html?userid=" + strUserid;
            break;
        case 3:
            strUrl = "qingjia.html?userid=" + strUserid;
            break;
    }
    window.location.href = strUrl;
}

//获取新闻列表
function GetNews(strDivId, json) {
    json = json.toJson(); //格式化
    var strInner = "";
    for (var i = 0; i < json.length; i++) {
        o1 = json[i];
        strInner = strInner + '<li><a href="../Manage/detail.aspx?id=' + o1["id"].toString() + '">' + o1["title"].toString() + '</a></li>';
    }

    $("#" + strDivId).html(strInner);
}

//获取新闻事项
function createUlContent(strDivId,json) {
    json = json.toJson(); //格式化
    var strInner = "";
    for (var i = 0; i < json.length; i++) {
        o1 = json[i];
        //strInner = strInner + '<li><a href="Manage/detail.aspx?id=' + o1["id"].toString() + '" title="' + o1["title"].toString() + '" target="_blank">' + o1["title"].toString() + '</a><span>' + o1["fbsj"].toString() + '</span></li>';

        strInner = strInner + '<tr><td><img src="imgs/New/hyxw_r7_c2.jpg"><td><td style="width:900px"><a href="Manage/detail.aspx?id=' + o1["id"].toString() + '" title="' + o1["title"].toString() + '" target="_blank">' + o1["title"].toString() + '</a></td><td><span>' + o1["fbsj"].toString() + '</span></td></tr>';


    }
    $("#" + strDivId).html(strInner);
}

//获取解决方案和经典案例
function createUlHtml(strDivId, json) {
    json = json.toJson(); //格式化
    var strInner = "";
    var type = 0;
    if (strDivId == "ulJdal")
    {
        type = 1;
    }
    for (var i = 0; i < json.length; i++) {
        o1 = json[i];
        strInner = strInner + "<li><a href=\"javascript:GetPubDetail("+type+",'" + o1["id"].toString() + "')\" title='" + o1["title"].toString() + "'>" +(i+1)+"、"+ o1["title"].toString() + "</a></li>";
    }
    $("#" + strDivId).html(strInner);
}

//表格滚动方法
function scrollText() {
    var speed = 50; //数字越大速度越慢
    var tab = document.getElementById("demo");
    var tab1 = document.getElementById("demo1");
    var tab2 = document.getElementById("demo2");
    //tab2.innerHTML = tab1.innerHTML; //克隆demo1为demo2
    function Marquee() {
        if (tab2.offsetTop - tab.scrollTop <= 0)//当滚动至demo1与demo2交界时
            tab.scrollTop -= tab1.offsetHeight //demo跳到最顶端
        else {
            tab.scrollTop++
        }
    }
    var MyMar = setInterval(Marquee, speed);
    tab.onmouseover = function () { clearInterval(MyMar) }; //鼠标移上时清除定时器达到滚动停止的目的
    tab.onmouseout = function () { MyMar = setInterval(Marquee, speed) }; //鼠标移开时重设定时器
}

//退出系统
function ExitSys() {
    window.close();
}

//获取当前日期
function GetCurrentDate() {
    var date = new Date();
    this.year = date.getFullYear();
    this.month = date.getMonth() + 1;
    this.date = date.getDate();
    this.day = new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六")[date.getDay()];
    this.hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
    this.minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
    this.second = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
    var currentTime = "今天是:" + this.year + "年" + this.month + "月" + this.date + "日 " + this.hour + ":" + this.minute + ":" + this.second + " " + this.day;
    return currentTime;
}

